package cn.gov.cbrc.east.test;

import java.sql.Connection;

import cn.gov.cbrc.core.db.DBUtil;
import cn.gov.cbrc.core.db.QueryRunnerUtil;

public class TableCreate {
	
	public static void createTable(){
		try {
			Connection conn = DBUtil.getConnection("check");
			String S_Table = "create table S_Table (_tableId,_tableCode,_tableName);";
			String S_Column = "create table S_Column (_tableCode,_colId,_colCode,_colName,_colIndex);";
			String S_Formula = "create table S_Formula (_colId,_formula,_formulaType,_formulaDesc);";
			QueryRunnerUtil.getInstance().update(conn, S_Table);
			QueryRunnerUtil.getInstance().update(conn, S_Column);
			QueryRunnerUtil.getInstance().update(conn, S_Formula);
			
		}
		catch (Exception e) {
			System.out.println(e);
		}finally{
			DBUtil.closeConnection("check");
		}
	}
	
	public static void dropTable(){
		try {
			Connection conn = DBUtil.getConnection("check");
			String S_Table = "drop table if exists S_Table;";
			String S_Column = "drop table if exists S_Column;";
			String S_Formula = "drop table if exists S_Formula;";
			QueryRunnerUtil.getInstance().update(conn, S_Table);
			QueryRunnerUtil.getInstance().update(conn, S_Column);
			QueryRunnerUtil.getInstance().update(conn, S_Formula);
		}
		catch (Exception e) {
			System.out.println(e);
		}finally{
			DBUtil.closeConnection("check");
		}
	}
	
	public static void main(String[] args){
		dropTable();
		createTable();
	}
	
}
